---莉莉 技能2 随机远程敌人 没有取最近敌人
---@class SkillEffect174102:BaseSkillEffect
SkillEffect174102 = ClientFight.CreateClass("SkillEffect174102",ClientFight.BaseSkillEffect)
local t = SkillEffect174102
---@param skill FightUsingSkill
---@param position Vector2
function t:prepareSkill(skill ,position)
    local fight = skill.fight
    local fighter = skill.fighter
    local target = skill.target
    local skillBean = skill.skill.skillBean
    -- 与目标间隔像素
    local interval = skillBean.f_SkillScriptParameter[1] / Global.TEN_THOUSANDTH;

    local leftOrRight = FighterUtils.leftOrRight1(fighter, target);

    local targetPos;
    if (leftOrRight == Global.LEFT) then
        targetPos = Vector2(target.position.x - interval, target.position.y);
    else
        targetPos = Vector2(target.position.x + interval, target.position.y);
    end
    -- 如果在边界以外
    if (FighterManager.checkOut(targetPos, fighter.shape, Global.FIGHT_INNER_ROUND, false, false)) then
        if (leftOrRight == Global.LEFT) then
            targetPos = Vector2(target.position.x + interval, target.position.y);
        else
            targetPos = Vector2(target.position.x - interval, target.position.y);
        end
    end
    -- 前摇阶段
    skill.stage = FightSkillStageEnum.PREPARE
    skill.targetDirection = leftOrRight
    skill.targetPosition = targetPos
    skill.skillShape = fighter.shape
    skill.separate = skillBean.f_SkillOut == 1
    skill.position = Vector2(position.x,position.y)

    local prepareTime = 0; --skill.skill.skillBean.f_PrepareTime
    local speed = skill.speed
    -- 计算攻击前摇帧数
    local frame =  math.ceil(prepareTime * speed / Global.FIGHT_FRAME);
    SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][SKILL]" .. fighter.fighterId .. "对" .. target.fighterId
    .. "攻击，使用技能" .. skillBean.f_SkillID .. "前摇阶段在" .. frame .. "帧后结束");
    if (frame > 0) then
        skill.stageFinishFrame = frame
    else
        SkillManager.releaseSkill(skill);
    end
    return true;
end

function t:releaseSkill(skill)
    return false
end
function t:attack(skill,target)
    return false
end
---@param fight Fight
---@param fighter Fighter
---@param skill FightSkill
---@param center Vector2
---@param excludes table<number,boolean>
---@return Fighter
function t:selectAttackTarget( fight, fighter, skill, center,excludes)
    local skillBean = skill.skillBean
    local targets = SkillManager.selectAttackTargets(fight, fighter, skill, skillBean.f_TargetRange,
            skillBean.f_Target, AttackUtils.getAttackRadius(fighter, skill),  AttackUtils.getAttackShape(fighter, skill),
            center, skillBean.f_TagActivate, nil);

    local resultFighter;

    -- 远程单位集合
    local rangedList = {}
    for k,target in pairs(targets) do
        if target:isRangedCLass() then
            table.insert(rangedList,target)
        end
    end
    if (#rangedList == 0) then
        resultFighter = targets[fight:random(#targets)]
    else
        resultFighter = rangedList[fight:random(#rangedList)];
    end

    return resultFighter;
end
t.New()